<template>
  <div class="app-container">
    <!--查询表单-->
    <!-- <el-form :inline="true" class="demo-form-inline">
      <el-form-item>
        <el-input v-model="searchObj.name" placeholder="用户名" />
      </el-form-item>

      <el-form-item>
        <el-select v-model="searchObj.level" clearable placeholder="用户身份">
          <el-option :value="1" label="房东" />
          <el-option :value="2" label="租客" />
        </el-select>
      </el-form-item>

      <el-button type="primary" icon="el-icon-search" @click="fetchData()">查询</el-button>
      <el-button type="default" @click="resetData()">清空</el-button>
    </el-form> -->
    <!-- 表格 -->
    <el-table
      v-loading="listLoading"
      :data="list"
      element-loading-text="数据加载中"
      border
      fit
      highlight-current-row
    >

      <el-table-column
        label="序号"
        width="70"
        align="center"
      >
        <template slot-scope="scope">
          {{ (page - 1) * limit + scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column prop="htype" label="类型" width="80" />
      <el-table-column prop="price" label="房租" width="80" />
      <el-table-column prop="chaoxiang" label="朝向" />

      <el-table-column prop="sed" label="押金" />
      <el-table-column prop="address" label="详细地址" />
      <el-table-column prop="utype" label="户型" />

      <el-table-column label="操作" width="230" align="center">
        <template slot-scope="scope">
          <el-button type="primary" size="mini" icon="el-icon-edit" @click="houseInfo(scope.row)">详情</el-button>
          <el-button type="warning" size="mini" icon="el-icon-check" @click="updateDataById(scope.row.houseId)">通过审核</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <el-pagination
      :current-page="page"
      :page-size="limit"
      :total="total"
      style="padding: 30px 0; text-align: center;"
      layout="total, prev, pager, next, jumper"
      @current-change="fetchData"
    />
    <!-- private int houseId;
    private String price;
    private int sed;
    private String leasing;
    private String utype;
    private String htype;
    private String chaoxiang;
    private String address;
    private String acreage;
    private String floors;
    private String roomNo;
    private String estate;
    private String hintroduce;
    private String jiadian;
    private String appraisals;
    private String statuss;
    private int ownerId;
    private int haudit;
    private String city;
    private String apply; -->
    <!-- 详细信息 -->
    <el-dialog title="房屋详细信息" :visible.sync="dialogFormVisible">
      <el-form :model="form">
        <el-form-item label="房东:" :label-width="formLabelWidth">
          {{ realName }}
        </el-form-item>
        <el-form-item label="房屋介绍:" :label-width="formLabelWidth">
          {{ form.hintroduce }}
        </el-form-item>
        <el-form-item label="户型：" :label-width="formLabelWidth">
          {{ form.utype }}
        </el-form-item>
        <el-form-item label="租赁方式:" :label-width="formLabelWidth">
          {{ form.leasing }}
        </el-form-item>
        <el-form-item label="租金:" :label-width="formLabelWidth">
          {{ form.price }}元/月
        </el-form-item>
        <el-form-item label="押金:" :label-width="formLabelWidth">
          {{ form.sed }}元
        </el-form-item>
        <el-form-item label="房屋类型:" :label-width="formLabelWidth">
          {{ form.htype }}
        </el-form-item>
        <el-form-item label="房子朝向:" :label-width="formLabelWidth">
          {{ form.chaoxiang }}
        </el-form-item>
        <el-form-item label="详细地址:" :label-width="formLabelWidth">
          {{ form.address }}
        </el-form-item>
        <el-form-item label="面积:" :label-width="formLabelWidth">
          {{ form.acreage }}平米
        </el-form-item>
        <el-form-item label="所在楼层:" :label-width="formLabelWidth">
          第{{ form.floors }}层
        </el-form-item>
        <el-form-item label="房间号:" :label-width="formLabelWidth">
          {{ form.roomNo }}
        </el-form-item>
        <el-form-item label="所在城市区域:" :label-width="formLabelWidth">
          {{ form.estate }}
        </el-form-item>

        <el-form-item label="拥有设备、家电:" :label-width="formLabelWidth">
          {{ form.jiadian }}
        </el-form-item>
        <el-form-item label="所属城市:" :label-width="formLabelWidth">
          {{ form.city }}
        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogFormVisible = false">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import house from '@/api/rental/house2'
import user from '@/api/rental/user'

// import skrollr from '@/views/edu/teacher'
export default {
  data() {
    return {
      listLoading: true, // 是否显示loading
      list: null, // 数据列表
      total: 0, // 总记录数
      page: 1, // 页码
      limit: 3, // 每页记录数
      searchObj: {}, // 查询条件
      dialogFormVisible: false,
      form: {}, // 详细信息
      realName: '', // 屋主
      formLabelWidth: '120px'
    }
  },
  created() { // 当页面加载时获取数据
    this.fetchData()
  },
  methods: {
    houseInfo(row) {
      user.getById(row.ownerId).then(response => {
        this.realName = response.data.realName
        console.log(response.data.realName)
      })
      this.form = row
      this.dialogFormVisible = true
    },
    fetchData(page = 1) { // 调用api层获取数据库中的数据
      console.log('加载列表' + page)
      // 当点击分页组件的切换按钮时，会传输一个当前的页码的参数page
      // 解决分页无效问题
      this.page = page
      this.listLoading = true
      console.log(this.searchObj.name)
      house.getAuditList().then(response => {
        console.log(response)
        if (response.code === 20000) {
          this.list = response.data
        }
        this.listLoading = false
      })
    },
    // 清空方法
    resetData() {
      this.searchObj = {}
      this.fetchData()
    },
    // 删除
    updateDataById(id) {
      console.log('dds=' + id)
      // 弹框
      this.$confirm('是否通过审核', '提示', {
        confirmButtonText: '通过',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        // 调用删除api
        return house.updateAudit(id)
      }).then(() => { // 如果上一个then成功则执行此处的then回调
        this.fetchData()
        this.$message({
          type: 'success',
          message: '审核通过!'
        })
      }).catch((response) => { // 失败
        if (response === 'cancel') {
          this.$message({
            type: 'info',
            message: '已取消'
          })
        }
      })
    },
    updatePermission(permis, userId) {
      console.log(permis + '  ' + userId)
      user.updateUserPermission(permis, userId).then(response => {
        if (response.code === 20000) {
          this.$message({
            type: 'success',
            message: response.message
          })
        }
      })
    }
  }
}

</script>
